<?php
/**
 * main.php - main page file, to verify login
 *
 * NMIT BIT Project - Infinity - A 3D Website using WebGL & HTML5 Technology
 * Infinity Grid Version 
 * Version: 1.0 Beta 2
 *
 * Infinity - Login function test
 *
 * Author: William Liu <qzliuyuzou@gmail.com> <lyzdev@gmail.com>
 *
 * Required Server Version:
 *  PHP5 or higher
 *  MySQL 5 or higher
 *
 * Required Browser Version:
 *  Google Chrome 9 or higher
 *  Mozilla Firefox 4 Beta or higher
 *  *Apple Safari
 *
 * Copyright (c) 2011, William Liu All rights reserved.
 * Infinity is an open source 3D website project
 * Under Apache License 2.0
 * http://www.lyzsoft.cn
 * http://7cloud.wordpress.com
 *
 * Project Starting date: 9/3/2011
 * Update Date 1: 6/4/2011
 * Update Date 2: 26/4/2011
 *
**/
?>

<?php  
session_start();  
if(isset($_SESSION['username']))  
{  
    @mysql_connect("localhost", "root","P@ssword1")               //mysql connection  
    or die("Database Connection Fail!");  
    @mysql_select_db("PRJ_Nova")                    //slect database  
    or die("The Database is not available!");  
	
    //Get Session  
    $username = $_SESSION['username']; 
	 
    //SQl query, to get user lvl  
    $query = @mysql_query("select user_level from users "."where username = '$username'")  
    or die("SQL query fail!");
	
    $row = mysql_fetch_array($query);  
    //Compare user lvl information between database and Sessipon, if is different, then update Session information
    if($row['user_level'] != $_SESSION['user_level'])  
    {  
        $_SESSION['user_level'] = $row['user_level'];  
    }  
    //Base on Session value to output different welcome information 
    if($_SESSION['user_level'] == 1)  
        echo "Welcome Administrator ".$_SESSION['username']. " " ."back!";  
    if($_SESSION['user_level'] == 0)  
        echo "Welcome User ".$_SESSION['username']. " " ."back!";  
    echo '</p><a href="logout.php">Logout</a>';  
}  
else  
{  
    echo "You do not have permission to access this page! Please login or register a new user!";
	echo '</p><a href="index.php">Login</a>';
	echo '</p><a href="register.php">Register</a>';
}  
?>